﻿var cateID = 0;
var learnLan = "";
var baseLan = "";
var active = false;
var name = "";
var Url = "";
var Desc = "";
var SortID = 0;

//判断是否能保存
var IsSave = true;

function onsuccResource(result)
{
    if(result!=null && result.PageID>0)
    {
        $get("PageTitle").value=result.PageTitle;
        PageID = result.PageID;
    }
    else
    {
        alert(NoPageID);
        IsSave=false;
    }
}
function SelectLan()
{
    learnLan=$get("SelectLearn").value;
    baseLan=$get("SelectBase").value;
    WebServices.WWW.Resources.GetResourcesPageToDT(learnLan,baseLan,onsuccResource);
}
function Save()
{
    if(Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    } 
    if(!$ValidButton$())return;   
    //if(!validationForm(new validationOptions('btnSubmit', '', true, ''))) return;
    if(IsSave)
    {        
        name=$get("txtName").value;
        Url=$get("txtUrl").value;
        Desc=$get("txtDes").value;
        learnLan=$get("SelectLearn").value;
        baseLan=$get("SelectBase").value;  
        cateID = $get("SelectCat").value;
        if($get("RInactive").checked)
        {
            active = false;
        }
        else if($get("RActive").checked)
        {
            active = true;
        }
        SortID = $get("txtSort").value;        
        if(SaveType==1)
        {//int resID, int pageID, int cateId, string url, string name, string description, string languageLearn, string baseLanguage, bool active, int sortID
            WebServices.WWW.Resources.UpdateResourcesAdmin(ResID,PageID,cateID,Url,name,Desc,learnLan,baseLan,active,SortID,onsuccRSave);
        }
        else if(SaveType==-1)
        {//int pageID, int cateId, string url, string name, string description, string languageLearn,string baseLanguage, int totalhits, bool active, int sortID
            WebServices.WWW.Resources.AddResource(PageID,cateID,Url,name,Desc,learnLan,baseLan,0,active,SortID,onsuccRSave)
        }            
    }
    else
    {
        return;
    }
}
function onsuccRSave(result)
{
    if(result.State)
    {
        $get("Succeed").style.display="";
        $get("failure").style.display="none";
    }
    else
    {
        $get("Succeed").style.display="none";
        $get("failure").style.display="";
    }
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();

